/* CODE MODIFIED FROM http://www.infernodevelopment.com/c-log-file-class-forget-debuggers*/

#include "LogFile.h"
bool statusTimeout = true;

LogFile::LogFile(string filename,int type) 
{

	if(type ==1)
	{			
		//open the LogFile file in append mode.
		m_stream.open(filename.c_str(),fstream::app);
		time_t t;
		time(&t);
		string separator ;
		separator = "\n\n\n************LogFile FILE FOR NODE STARTED AT ";
		separator+=ctime(&t);
		separator+="**********************\n\n";
		m_stream<<separator;
		m_stream.flush();
	}
	
	//open the status file in create mode
	else if(type==2)	
	{				
		m_stream.open(filename.c_str());
	}
	else if(type==3)
	{
		m_stream.open(filename.c_str(),fstream::app);
	}
}

void LogFile::WriteFilen(string logline)
{
  m_stream << logline << endl;
  m_stream.flush();
}

void LogFile::WriteFile(string logline)
{
  m_stream << logline;
  m_stream.flush();
}

void LogFile::WriteFile(char logline)
{
  m_stream << logline;
  m_stream.flush();
}

void LogFile::WriteFilen(uint32_t logline)
{
  m_stream << logline << endl;
  m_stream.flush();
}

void LogFile::WriteFile(uint32_t logline)
{
  m_stream << logline<<" ";
  m_stream.flush();
}

void LogFile::WriteFile(int port)
{
	m_stream << port<<" ";
	m_stream.flush();
}

void LogFile::WriteFilen(string line1,string line2,string line3)
{
	m_stream<<line1<<" "<<line2<<" "<<line3<<endl;
	m_stream.flush();
}
void LogFile::WriteFile(string line1,string line2,string line3)
{
	m_stream<<line1<<" "<<line2<<" "<<line3;
	m_stream.flush();
}

// void LogFile::Close()
// {
	// if(isStatusfileOpen==true)
	// {
		// isStatusfileOpen=false;
		// m_stream.close();
	// }

// }

LogFile::~LogFile()
{
		if(m_stream.is_open())
			m_stream.close();
}

/*CODE MODIFIED FROM http://www.infernodevelopment.com/c-LogFile-file-class-forget-debuggers */

